<template>
  <!-- fqc及oqc检验单界面 -->
  <div>
    <basic-container>
      <avue-crud
        :option="option"
        :table-loading="loading"
        :search.sync="query"
        :data="data"
        :page.sync="page"
        :before-open="beforeOpen"
        v-model="form"
        ref="crud"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        @on-load="onLoad"
        :key="timer"
      >
        <template slot="menuRight">
          <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" v-if="permission.fqcCheckList_view" icon="el-icon-finished" size="small" @click.stop="handleResult(scope.row)">处理结果 </el-button>
          <el-button type="text" v-if="permission.fqcCheckList_view" icon="el-icon-view" size="small" @click.stop="handleView(scope.row)">查看 </el-button>
        </template>
      </avue-crud>
      <el-dialog ref="dialog" title="查看" append-to-body :visible.sync="showDialog" v-if="showDialog" :close-on-click-modal="dialogClose">
        <el-tabs type="card" v-if="showDialog" @tab-click="handleTabClick($event)" v-model="tabsIndex">
          <el-tab-pane label="检验项详情" name="1">
            <avue-form ref="aplProperties" v-model="viewModel" :option="viewOption">
              <template slot="info" v-if="viewModel.attributeResultVOList && viewModel.attributeResultVOList.length > 0">
                <avue-form
                  ref="itemProperties"
                  v-for="(item, index) in viewModel.attributeResultVOList || []"
                  v-model="viewModel.attributeResultVOList[index]"
                  :option="itemOption"
                  :key="index"
                >
                  <template slot="info2">
                    <span style="display: block">检验项： {{ item.item ? item.item.itemName : '' }}</span>
                    <span style="display: block">检验明细项：{{ item.itemAttribute.attributeName }}</span>
                    <span style="display: block">检验标准：{{ item.testCriterion }}</span>
                    <span style="display: block">检验工具：{{ item.itemAttribute.testTool }}</span>
                    <div v-if="item.examineRealValue.type === 'SINGLE-INPUT'">
                      <div v-for="(scanItem, index2) in item.examineRealValue.options" :key="index2">
                        <label>{{ scanItem.label }}：</label>
                        <el-input style="width: 200px; margin-bottom: 5px" :value="scanItem.value" :disabled="true"> </el-input>
                      </div>
                    </div>
                    <div v-if="item.examineRealValue.type === 'MULTIPLE-INPUT'">
                      <div v-for="(scanItem, index2) in item.examineRealValue.options" :key="index2" style="margin-bottom: 5px">
                        <label>{{ scanItem.label }}：</label>
                        <table border="1">
                          <tr>
                            <th width="50" style="text-align: center">次数</th>
                            <th width="70" style="text-align: center">测试值</th>
                            <th width="120" style="text-align: center">测试结果</th>
                            <th width="70" style="text-align: center">操作</th>
                          </tr>
                          <tr v-for="(result, index3) in item.examineRealValue.options[index2].valueResults" :key="index3">
                            <td style="text-align: center">{{ result.sequence }}</td>
                            <td style="text-align: center">{{ result.value }}</td>
                            <td style="text-align: center">
                              <span>{{ result.result }}</span>
                              <!-- <span style="margin-right: 2px"><input checked type="radio"/>OK</span> <span><input type="radio"/>NG</span> -->
                            </td>
                            <td style="text-align: center; color: red"><div>x</div></td>
                          </tr>
                        </table>
                      </div>
                    </div>
                    <div v-if="item.examineRealValue.type === 'RADIO'">
                      <div v-for="(scanItem, index2) in item.examineRealValue.options" :key="index2">
                        <label>{{ scanItem.label }}：</label>
                        <el-radio v-model="scanItem.valueResults" disabled :label="scanItem.realLabel">{{ scanItem.realLabel }}</el-radio>
                        <el-radio v-model="scanItem.valueResults" disabled :label="scanItem.shamLabel">{{ scanItem.shamLabel }}</el-radio>
                      </div>
                    </div>
                    <div v-if="item.examineRealValue.type === 'SCAN'">
                      <div v-for="(scanItem, index2) in item.examineRealValue.options" :key="index2">
                        <label>{{ scanItem.label + '数量' }}：</label>
                        <el-input style="width: 200px" :value="item.examineRealValue.scanContent.length" :disabled="true"> </el-input>
                      </div>
                    </div>
                    <div>
                      <label>不良登记：</label>
                      <table border="1">
                        <tr>
                          <th width="120" style="text-align: center">严重程度</th>
                          <th width="70" style="text-align: center">不良数量</th>
                          <th width="70" style="text-align: center">条码类型</th>
                          <th width="400" style="text-align: center">不良条码</th>
                        </tr>
                        <tr>
                          <td style="text-align: center">严重问题（CRI）</td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].criQuantity || '' }}</td>
                          <td style="text-align: center">
                            {{ viewModel.attributeResultVOList[index].criList.length > 0 && viewModel.attributeResultVOList[index].criList[0].objectType | packTypefilter }}
                          </td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].criList | defectfilter }}</td>
                        </tr>
                        <tr>
                          <td style="text-align: center">主要问题（MAJ）</td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].majQuantity || '' }}</td>
                          <td style="text-align: center">
                            {{ viewModel.attributeResultVOList[index].majList.length > 0 && viewModel.attributeResultVOList[index].majList[0].objectType | packTypefilter }}
                          </td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].majList | defectfilter }}</td>
                        </tr>
                        <tr>
                          <td style="text-align: center">次要问题（MIN）</td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].minQuantity || '' }}</td>
                          <td style="text-align: center">
                            {{ viewModel.attributeResultVOList[index].minList.length > 0 && viewModel.attributeResultVOList[index].minList[0].objectType | packTypefilter }}
                          </td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].minList | defectfilter }}</td>
                        </tr>
                      </table>
                    </div>
                  </template>
                </avue-form>
              </template>
              <template slot="info" v-else>
                <span></span>
              </template>
              <template slot="attachments">
                <div>
                  <div style="display: inline-block; text-align: center" v-for="(item, index) in viewModel.attachments" :key="item.attachmentId">
                    <img style="width: 100px; height: 100px; padding-right: 10px; display: block" :src="item.link" @click="openPreview(index, item.link)" />
                    <!-- <el-button type="text" v-if="item.link" icon="el-icon-download" size="small" @click="handleDownload(item)">下载 </el-button> -->
                  </div>
                </div>
              </template>
            </avue-form>
          </el-tab-pane>
          <el-tab-pane label="条码记录" name="2">
            <avue-form v-model="detailData" :option="detailOption"></avue-form>
          </el-tab-pane>
          <el-tab-pane label="AQL" name="3">
            <div v-for="(item, index) in inspectionAqlList" :key="index">
              <avue-form v-model="inspectionAqlList[index]" :option="aqlOption"> </avue-form>
            </div>
          </el-tab-pane>
        </el-tabs>
        <span slot="footer" class="dialog-footer">
          <el-button size="small" @click="showDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
        </span>
      </el-dialog>
      <el-dialog ref="dialog" title="处理结果" append-to-body :visible.sync="showHandleResultDialog" v-if="showHandleResultDialog" :close-on-click-modal="false">
        <avue-crud
          :option="handleResultOption"
          :search.sync="query"
          :data="handleResultData"
          v-model="form"
          ref="crud2"
          @search-change="searchDialogChange"
          @search-reset="searchDialogReset"
          @selection-change="selectionDialogChange"
          :key="timer"
        >
          <template slot="menuLeft">
            <el-button type="primary" v-if="permission.fqcCheckList_view" size="small" @click.stop="extendedInsurance()">延 保</el-button>
            <el-button type="primary" v-if="permission.fqcCheckList_view" size="small" @click.stop="handleScrap()">报废登记 </el-button>
          </template>
        </avue-crud>
      </el-dialog>
      <el-dialog ref="dialog" width="25%" :title="title" append-to-body :visible.sync="commonDialog" v-if="commonDialog" :close-on-click-modal="false">
        <avue-form ref="detailData" v-model="detailData" :option="commonOption"></avue-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" size="small" @click="handleSubmit"><i class="el-icon-circle-plus-outline"></i><span>提 交</span></el-button>
          <el-button size="small" @click="commonDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
        </span>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import { getPage, getDetail, getList, extension, scrap, getAqlInfo, getQcCalculateAqlInfo } from '@/api/quality/inspection-records.js';

import { mapGetters } from 'vuex';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';

export default {
  inject: ['reload'],
  filters: {
    packTypefilter(type) {
      switch (type) {
        case 'PACKING':
          return '包装条码';
        case 'PRODUCT':
          return '产品';
        case 'CARRIER':
          return '载具';
        default:
          break;
      }
    },
    defectfilter(data) {
      let arr = data || [];
      let objectSns = arr.map((item) => {
        return item.objectSn;
      });
      return String(objectSns);
    }
  },
  components: {
    userTableConfig
  },
  mixins: [userConfig()],
  data() {
    return {
      pageCode: 'INSPECTION_RECORD',
      form: {
        deptId: '',
        lineId: ''
      },
      search: {},
      dialogQuery: {},
      query: {},
      inspection: {},
      loading: true,
      isLock: true,
      title: '',
      tabsIndex: '1',
      selectionDialogList: [],
      inspectionAqlList: [],
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      aqlModel: {
        attributeResultVOList: [{}]
      },
      viewModel: {},
      selectionList: [],
      showHandleResultDialog: false,
      commonDialog: false,
      commonOption: {},
      handleResultData: [],
      itemOption: {
        emptyBtn: false,
        submitBtn: false,
        labelWidth: '160',
        column: [
          {
            labelWidth: 60,
            label: '',
            prop: 'info2',
            span: 24,
            hide: true
          },
          {
            label: '检验结果',
            prop: 'examineResult',
            type: 'radio',
            span: 24,
            disabled: true,
            labelWidth: 100,
            row: true,
            formslot: true,
            dicData: [
              {
                label: 'OK',
                value: 'OK'
              },
              {
                label: 'NG',
                value: 'NG'
              }
            ]
          }
        ]
      },
      aqlOption: {
        emptyBtn: false,
        submitBtn: false,
        column: [
          {
            label: '严重程度',
            prop: 'severityCode',
            span: 8,
            labelWidth: 160,
            type: 'select',
            row: true,
            disabled: true,
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_plan',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '检验水平',
            prop: 'levelType',
            span: 8,
            row: true,
            labelWidth: 160,
            disabled: true,
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=aql_inspection_level',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '检验水平代码',
            prop: 'levelCode',
            span: 8,
            row: true,
            labelWidth: 160,
            disabled: true
          },
          {
            label: '质量水平代码',
            prop: 'limitCode',
            labelWidth: 160,
            span: 8,
            disabled: true
          },
          {
            label: '抽检数量',
            prop: 'sampleQuantity',
            span: 6,
            labelWidth: 80,
            disabled: true
          },
          {
            label: 'Ac',
            prop: 'acceptQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: 'Re',
            prop: 'rejectQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: '严重缺陷抽样水平代码',
            prop: 'severityLimitCode',
            labelWidth: 160,
            span: 8,
            disabled: true
          },
          {
            label: '抽检数量',
            prop: 'severitySampleQuantity',
            span: 6,
            labelWidth: 80,
            disabled: true
          },
          {
            label: 'Ac',
            prop: 'severityAcceptQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: 'Re',
            prop: 'severityRejectQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: '主要缺陷抽样水平代码',
            prop: 'majorLimitCode',
            labelWidth: 160,
            span: 8,
            disabled: true
          },
          {
            label: '抽检数量',
            prop: 'majorSampleQuantity',
            span: 6,
            labelWidth: 80,
            disabled: true
          },
          {
            label: 'Ac',
            prop: 'minorAcceptQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: 'Re',
            prop: 'majorRejectQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: '次要缺陷抽样水平代码',
            prop: 'minorLimitCode',
            labelWidth: 160,
            span: 8,
            disabled: true
          },
          {
            label: '抽检数量',
            prop: 'minorSampleQuantity',
            span: 6,
            labelWidth: 80,
            disabled: true
          },
          {
            label: 'Ac',
            prop: 'minorAcceptQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: 'Re',
            prop: 'minorRejectQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          }
        ]
      },
      viewOption: {
        emptyBtn: false,
        submitBtn: false,
        labelWidth: '160',
        column: [
          {
            labelWidth: 60,
            label: '',
            prop: 'info',
            span: 24,
            hide: true,
            row: true,
            formslot: true
          },
          {
            label: '综合判定结果',
            prop: 'examineResult',
            type: 'radio',
            span: 24,
            disabled: true,
            labelWidth: 100,
            row: true,
            dicData: [
              {
                label: 'OK',
                value: 'OK'
              },
              {
                label: 'NG',
                value: 'NG'
              }
            ]
          },
          // {
          //   label: '综合判定结果',
          //   prop: 'examineResult',
          //   type: 'radio',
          //   span: 24,
          //   disabled: true,
          //   labelWidth: 100,
          //   row: true,
          //   dicData: [
          //     {
          //       label: 'OK',
          //       value: 'OK'
          //     },
          //     {
          //       label: 'NG',
          //       value: 'NG'
          //     }
          //   ]
          // },
          {
            label: '附件',
            prop: 'attachments',
            span: 24,
            formslot: true,
            disabled: true
          },
          {
            label: '备注/原因',
            prop: 'remark',
            span: 20,
            type: 'textarea',
            maxRows: 3,
            minRows: 3,
            disabled: true,
            row: true
          }
        ]
      },
      handleResultOption: {
        menu: false,
        addBtn: false,
        border: true,
        tip: false,
        selection: true,
        height: 300,
        searchMenuPosition: 'right',
        dialogClickModal: false,
        refreshBtn: false,
        column: [
          {
            label: '条码类型',
            prop: 'objectType',
            dicData: [
              {
                label: '产品',
                value: 'PRODUCT'
              },
              {
                label: '包装',
                value: 'PACKING'
              },
              {
                label: '载具',
                value: 'CARRIER'
              }
            ]
          },
          {
            label: '条码',
            prop: 'objectSn',
            search: true,
            searchOrder: 2
          },
          {
            label: '数量',
            prop: 'objectQuantity'
          },
          {
            label: '检验结果',
            prop: 'isNg',
            type: 'select',
            search: true,
            searchOrder: 1,
            dicData: [
              {
                label: '合格',
                value: false
              },
              {
                label: '不合格',
                value: true
              }
            ]
          },
          {
            label: '处理结果',
            prop: 'status',
            type: 'select',
            dicData: [
              {
                label: '待处理',
                value: 1
              },
              {
                label: '待报废',
                value: 2
              },
              {
                label: '已延保',
                value: 3
              }
            ]
          }
        ]
      },
      option: {
        height: 'calc(100vh - 485px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 18,
        searchMenuPosition: 'right',
        border: true,
        index: true,
        indexLabel: '序号',
        selection: true,
        dialogClickModal: false,
        labelWidth: 120,
        searchSpan: 6,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        // 查看
        viewBtn: false,
        menuWidth: 160,
        columnBtn: false,
        column: [
          {
            label: '检验单号',
            prop: 'documentNo',
            search: true,
            minWidth: 150,
            searchOrder: 1
          },
          {
            label: '物料编码',
            prop: 'partNo',
            minWidth: 100,
            search: true,
            searchOrder: 2
          },
          {
            label: '物料名称',
            minWidth: 100,
            prop: 'partName',
            search: true,
            searchOrder: 3
          },
          {
            label: '物料批次',
            minWidth: 100,
            prop: 'lotNo'
          },
          {
            label: '物料规格',
            minWidth: 100,
            prop: 'partModel'
          },
          {
            label: '送检数量',
            prop: 'sendExamineQuantity'
          },
          {
            label: '检验方式',
            prop: 'examineMode',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=inspection_mode',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '检验日期',
            minWidth: 150,
            prop: 'examineDate',
            type: 'datetime',
            search: true,
            searchOrder: 4,
            searchType: 'daterange',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            startPlaceholder: '开始日期',
            endPlaceholder: '结束日期'
          },
          {
            label: '检验结果',
            prop: 'examineResult',
            type: 'select',
            search: true,
            searchOrder: 6,
            dicUrl: '/api/blade-system/dict/dictionary?code=examineResult',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          }
        ]
      },
      data: [],
      dialogVisible: false,
      dialogForm: {
        isQualified: null
      },
      // 车间列表
      workshopList: [],
      repairSuccessVisible: false,
      repairSuccessForm: {
        scrapReason: ''
      },
      rulesSuccessForm: {
        scrapReason: [{ required: true, message: '请输入报废原因', trigger: 'blur' }]
      },
      // 判断是在那个routeName下的
      selectRouteObj: {
        documentType: 'ODQC'
      },
      timer: new Date().getTime(),
      showDialog: false,
      detailData: {},
      detailOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: '130',
        column: [
          {
            label: '检验条码',
            prop: 'objectSn',
            type: 'textarea',
            rows: 5,
            span: 24,
            disabled: true,
            placeholder: '检验条码'
          },
          {
            label: '不良条码',
            prop: 'NGSn',
            type: 'textarea',
            rows: 5,
            span: 24,
            disabled: true,
            placeholder: '不良条码'
          }
        ]
      },
      commonOption: {
        submitBtn: false,
        emptyBtn: false,
        type: 'number',
        controls: false,
        labelWidth: '130',
        column: [
          {
            label: '延长保质天数',
            prop: 'extensionDays',
            type: 'number',
            controls: false,
            row: true,
            placeholder: '请填写',
            rules: [
              {
                required: true,
                message: '请输入延长保质天数',
                trigger: 'blur'
              },
              {
                required: true,
                trigger: 'blur',
                validator: (rule, value, callback) => {
                  let reg = /^\+?[1-9]\d*$/;
                  console.log(value, 888);
                  if (!reg.test(value)) {
                    callback(new Error('请输入正整数'));
                  } else {
                    callback();
                  }
                }
              }
            ]
          },
          {
            label: '报废原因',
            prop: 'reason',
            type: 'textarea',
            row: true,
            placeholder: '请填写'
          }
        ]
      }
    };
  },
  computed: {
    ...mapGetters(['permission']),
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids;
    }
  },
  watch: {},
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  methods: {
    init() {},
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchDialogReset() {
      this.dialogQuery = {};
      this.getInspectList(this.inspection.id);
    },
    searchChange(params, done) {
      if (params.examineDate && params.examineDate.length > 0) {
        params.startExamineDate = params.examineDate[0];
        params.endExamineDate = params.examineDate[1];
        delete params.examineDate;
      }
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    searchDialogChange(params, done) {
      this.dialogQuery = params;
      this.getInspectList(this.inspection.id);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionDialogChange(list) {
      this.selectionDialogList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      this.query.documentType = this.selectRouteObj.documentType;
      this.query.descs = 'examine_date';
      this.query.statusStr = 2;
      getPage(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    recheck() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        if (ele.status === 2) {
          ids.push(ele.id);
        }
      });
      if (ids.length < 1) {
        this.$message({
          type: 'warning',
          message: '请确保选择的数据是已检验的！'
        });
        return;
      }
      this.$confirm('确定将选择数据重检?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          //   return repeatExam(ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        });
    },
    newKey() {
      this.timer = new Date().getTime();
    },
    handleView(row) {
      this.inspection.rowData = row;
      this.tabsIndex = '1';
      getDetail(row.id).then((res) => {
        let data = res.data.data;
        this.viewModel = data;
        this.inspectionAqlList = data.inspectionAqlList || [];
        this._forEach(this.viewModel.attributeResultVOList || [], (item) => {
          if (!item.criList) {
            item.criList = [];
          }
          if (!item.majList) {
            item.majList = [];
          }
          if (!item.minList) {
            item.minList = [];
          }
          item.examineRealValue = JSON.parse(item.examineRealValue);
        });

        let objectSn = [];
        let NGSn = [];
        this._forEach(data.inspectionObjectList, (item) => {
          objectSn.push(item.objectSn);
          if (item.isNg) {
            NGSn.push(item.objectSn);
          }
        });
        this.detailData.objectSn = objectSn.join('、');
        this.detailData.NGSn = NGSn.join('、');
      });

      this.showDialog = true;
    },
    handleResult(row) {
      this.dialogQuery = {};
      this.showHandleResultDialog = true;
      this.inspection.id = row.id;
      this.getInspectList(row.id);
    },
    getInspectList(id) {
      getList({
        inspectionDocumentId: id,
        ...this.dialogQuery
      }).then((res) => {
        let data = res.data.data;
        this.handleResultData = data;
      });
    },
    async handleTabClick({ index }) {},
    //延保
    extendedInsurance() {
      if (this.selectionDialogList.length === 0) {
        this.$message.warning('至少选择一条数据');
        return;
      }
      this.title = '延保';
      let dayObj = this.findObject(this.commonOption.column, 'extensionDays');
      let remarkObj = this.findObject(this.commonOption.column, 'reason');
      dayObj.display = true;
      remarkObj.display = false;
      this.commonDialog = true;
    },
    //报废登记
    handleScrap() {
      if (this.selectionDialogList.length === 0) {
        this.$message.warning('至少选择一条数据');
        return;
      }
      this.title = '报废登记';
      let dayObj = this.findObject(this.commonOption.column, 'extensionDays');
      let remarkObj = this.findObject(this.commonOption.column, 'reason');
      dayObj.display = false;
      remarkObj.display = true;
      this.commonDialog = true;
    },
    openPreview(index = 0, link) {
      this.$ImagePreview([{ url: link }], index, {
        closeOnClickModal: false
      });
    },
    handleSubmit() {
      this.$refs.detailData.validate((bol, obj) => {
        if (bol) {
          if (this.title === '延保') {
            // if (!this.detailData.extensionDays && this.detailData.extensionDays !== 0) {
            //   this.$message({
            //     type: 'warning',
            //     message: '请填写延长保质天数!'
            //   });
            //   return;
            // }
            let packingIdList = this._map(this.selectionDialogList, (item) => {
              return item.id;
            });
            extension(packingIdList, this.detailData.extensionDays).then((res) => {
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
              if (this.inspection.id) {
                this.getInspectList(this.inspection.id);
                this.$refs.crud2.toggleSelection();
              }
            });
          } else {
            let params = this._map(this.selectionDialogList, (item) => {
              return item.id;
              //    {
              //     objectId: item.objectId
              //     // objectSn: item.objectSn,
              //     // objectType: item.objectType,
              //     // objectSubType: item.objectType === 'PACKING' ? 'MATERIAL' : 'PRODUCT',
              //     // remark: this.detailData.reason
              //   };
            });
            scrap(params, this.detailData.reason).then((res) => {
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
              if (this.inspection.id) {
                this.getInspectList(this.inspection.id);
                this.$refs.crud2.toggleSelection();
              }
            });
          }
          this.$refs.detailData.resetForm();
          this.commonDialog = false;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-col-md-12 {
  width: 90% !important;
}
</style>
